// 对账函
import ModuleTemplate from '@/utils/ModuleTemplate';
import appService from '@/utils/appService';
import systemConfig from '@/utils/config';

/* eslint-disable */
/** modules名称空间 */
export const namespace = 'reconciliation';
const model = {
    name: namespace,
    /** 基本属性 */
    state: {
        /** 分页数据查询条件 */
        query: {
            currentPage: 1,
            pageSize: 50
        }
    },
    /** 从基本数据派生的数据,getters接收state作为其第一个参数，
     * 接受其他 getters 作为第二个参数，如不需要，第二个参数可以省略
     */
    getters: {},
    /** 执行同步操作，包含用于直接修改state的函数 */
    mutations: {
        /** 加载更多的时候，拿之前的数据和请求回来的数据拼接 **/
        pushDataToList(store, data) {
            store.pageInfo.list = store.pageInfo.list.concat(data);
        },
    },
    /** 异步操作，可调用同步操作函数 */
    actions: {
        // 城市
        getCityData (store, payload) {
            return new Promise((resolve, reject) => {
                appService.getRequest(`${config.dataSource}/trade-merchant/common/getCity`, payload).then((result) => {
                    if (result && result.status === 200) {
                        resolve(result);
                    } else {
                        reject(Error);
                    }
                });
            });
        },
        // 商户
        getMerchList (store, payload) {
            return new Promise((resolve, reject) => {
                appService.getRequest(`${config.dataSource}/trade-merchant/admin/merchant/findPageList`, payload).then((result) => {
                    if (result && result.status === 200) {
                        resolve(result);
                    } else {
                        reject(Error);
                    }
                });
            });
        },
        // 业务场景
        getScenarioList (store, payload) {
            return new Promise((resolve, reject) => {
                appService.getRequest(`${config.dataSource}/trade-merchant/admin/property/dictionary`, payload).then((result) => {
                    if (result && result.status === 200) {
                        resolve(result);
                    } else {
                        reject(Error);
                    }
                });
            });
        },
        // 删除对账函
        cancel (store, payload) {
            return new Promise((resolve, reject) => {
                appService.deleteRequest(`${config.dataSource}/trade-settlement/admin/statement/`, payload).then((result) => {
                    if (result && result.status === 200) {
                        resolve(result);
                    } else {
                        reject(Error);
                    }
                });
            });
        },
        // 删除对账函 - 修改接口 批量处理 post
        cancelRemove (store, payload) {
            return new Promise((resolve, reject) => {
                appService.postRequest(`${config.dataSource}/trade-settlement/admin/statement/remove`, payload).then((result) => {
                    if (result && result.status === 200) {
                        resolve(result);
                    } else {
                        reject(Error);
                    }
                });
            });
        },
        // 生成
        generate (store, payload) {
            return new Promise((resolve, reject) => {
                appService.postRequest(`${config.dataSource}/trade-settlement/admin/statement/`, payload).then((result) => {
                    if (result && result.status) {
                        resolve(result);
                    } else {
                        reject(Error);
                    }
                });
            });
        },
        /** 点击加载更多 **/
        getMoreList(store, payload) {
            return new Promise((resolve, reject) => {
                appService.getRequest(`${config.dataSource}/trade-settlement/admin/statement/findPageList`, payload).then(result => {
                    if (result && result.status) {
                        resolve(result);
                    } else {
                        reject(result.data.msg);
                    }
                });
            });
        },
        /** 导出PDF **/
        exportPdf(store, payload) {
            return new Promise((resolve, reject) => {
                appService.getRequest(`${config.dataSource}/trade-settlement/admin/statement/statementAccountPdf`, payload, { responseType: 'arraybuffer' }).then(result => {
                    if (result && result.status === 200) {
                        resolve(result);
                    } else {
                        reject(Error);
                    }
                });
            });
        }
    },
    /** 子模块 */
    modules: {
    }
};
const config = {
    /** 数据源，对应后端controller类的请求映射,
     * 如果不指定则默认和name一样
     */
    /* eslint-disable */
    dataSource: systemConfig.serverProxy ,
    // dataSource: systemConfig.tradeInvoicePath,
    invoiceServer: true,
    /** query函数调用的后端controller方法的请求映射 */
    queryMethod: '/trade-settlement/admin/statement/findPageList',
    updateMethod: null,
    deleteMethod: null,
    saveMethod: '/trade-settlement/admin/statement/',
    getDetailMethod: null
};
const moduleTemplate = new ModuleTemplate(model, config);
export const module = moduleTemplate.createModel();
